The CL package defines a version
of the Common Lisp typep predicate.
Check if object is of type type, where type is a (quoted) type name of the sort used by Common Lisp. For example,
(typep foo 'integer)is equivalent to(integerp foo).
The type argument to the above function is either a symbol or a list beginning with a symbol.
t stands for the union of all
types. (typep object t) is
always true. Likewise, the type symbol nil stands
for nothing at all, and (typep object
nil) is always false.null represents the symbol
nil. Thus (typep object
'null) is equivalent to (null
object).atom represents all objects
that are not cons cells. Thus (typep
object 'atom) is equivalent to
(atom object).real is a synonym for
number, and fixnum is a synonym for
integer.character and
string-char match integers in the range from 0 to
255.float uses the
floatp-safe predicate defined by this package
rather than floatp, so it will work correctly even
in Emacs versions without floating-point support.(integer low
high) represents all integers between
low and high, inclusive. Either bound may
be a list of a single integer to specify an exclusive limit, or
a * to specify no limit. The type (integer *
*) is thus equivalent to integer.float,
real, or number represent numbers of
that type falling in a particular range.and, or, and
not form combinations of types. For example,
(or integer (float 0 *)) represents all objects
that are integers or non-negative floats.member or
member* represent objects eql to any
of the following values. For example, (member 1 2 3
4) is equivalent to (integer 1 4), and
(member nil) is equivalent to
null.(satisfies
predicate) represent all objects for
which predicate returns true when called with that
object as an argument.The following function and macro (not technically predicates)
are related to typep.
This function attempts to convert object to the specified type. If object is already of that type as determined by
typep, it is simply returned. Otherwise, certain types of conversions will be made: If type is any sequence type (string,list, etc.) then object will be converted to that type if possible. If type ischaracter, then strings of length one and symbols with one-character names can be coerced. If type isfloat, then integers can be coerced in versions of Emacs that support floats. In all other circumstances,coercesignals an error.
This macro defines a new type called name. It is similar to
defmacroin many ways; when name is encountered as a type name, the body forms are evaluated and should return a type specifier that is equivalent to the type. The arglist is a Common Lisp argument list of the sort accepted bydefmacro*. The type specifier ‘(name args...)’ is expanded by calling the expander with those arguments; the type symbol ‘name’ is expanded by calling the expander with no arguments. The arglist is processed the same as fordefmacro*except that optional arguments without explicit defaults use*instead ofnilas the “default” default. Some examples:(deftype null () '(satisfies null)) ; predefined (deftype list () '(or null cons)) ; predefined (deftype unsigned-byte (&optional bits) (list 'integer 0 (if (eq bits '*) bits (1- (lsh 1 bits))))) (unsigned-byte 8) == (integer 0 255) (unsigned-byte) == (integer 0 *) unsigned-byte == (integer 0 *)The last example shows how the Common Lisp
unsigned-bytetype specifier could be implemented if desired; this package does not implementunsigned-byteby default.
The typecase and check-type macros
also use type names. See Conditionals. See Assertions. The
map, concatenate, and
merge functions take type-name arguments to specify
the type of sequence to return. See Sequences.